package com.hmdp.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmdp.dto.Result;
import com.hmdp.dto.UserDTO;
import com.hmdp.entity.Blog;
import com.hmdp.entity.User;
import com.hmdp.service.IBlogService;
import com.hmdp.service.IUserService;
import com.hmdp.constants.SystemConstants;
import com.hmdp.utils.UserHolder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/blog")
public class BlogController {

    @Resource
    private IBlogService blogService;
    @Resource
    private IUserService userService;


    /**
     * 查看探店笔记
     *
     * @author Yhans
     * @date 2024/2/24 21:40
     */
    @GetMapping("/{id}")
    public Result queryBlog(@PathVariable("id") Long id) {
        return blogService.queryBlog(id);
    }

    /**
     * 发布探店笔记
     *
     * @author Yhans
     * @date 2024/2/24 21:40
     */
    @PostMapping
    public Result saveBlog(@RequestBody Blog blog) {
        return blogService.saveBlog(blog);
    }

    /**
     * 用户点赞
     *
     * @author Yhans
     * @date 2024/2/25 10:50
     */
    @PutMapping("/like/{id}")
    public Result likeBlog(@PathVariable("id") Long id) {
        return blogService.likeBlog(id);
    }

    /**
     * 查询博客的点赞列表
     *
     * @author Yhans
     * @date 2024/2/25 10:49
     */
    @GetMapping("/likes/{id}")
    public Result queryBlogLikeList(@PathVariable("id") Long id) {
        return blogService.queryBlogLikeList(id);
    }

    /**
     * 查询自己发布的博客
     *
     * @author Yhans
     * @date 2024/2/25 10:56
     */
    @GetMapping("/of/me")
    public Result queryMyBlog(@RequestParam(value = "current", defaultValue = "1") Integer current) {
        return blogService.queryMyBlog(current);
    }

    /**
     * 查询热点笔记
     *
     * @author Yhans
     * @date 2024/2/25 10:55
     */
    @GetMapping("/hot")
    public Result queryHotBlog(@RequestParam(value = "current", defaultValue = "1") Integer current) {
        return blogService.queryHotBlog(current);
    }

    /**
     * 查询其他用户主页的博客
     *
     * @author Yhans
     * @date 2024/2/25 16:14
     */
    @GetMapping("/of/user")
    public Result queryOtherUserBlogs(@RequestParam("id") Long id, @RequestParam(value = "current", defaultValue = "1") Integer current) {
        return blogService.queryOtherUserBlogs(id,current);
    }

    /**
     * 滚动分页查询
     * @author Yhans
     * @date 2024/2/26 15:33
     * @param max 上一次查询的最小时间戳
     * @param offset 偏移量
     * @return Result
     */
    @GetMapping("/of/follow")
    public Result queryBlogOfFollow(
            @RequestParam("lastId") Long max, @RequestParam(value = "offset", defaultValue = "0") Integer offset){
        return blogService.queryBlogOfFollow(max, offset);
    }

}
